//
//  CellForSPMusic.m
//  StayAwhile
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellForSPMusic.h"
#import "TXPSPMusic.h"
#import "TXPLBfit.h"
@interface CellForSPMusic ()
@property(nonatomic,strong)UILabel *nameLaber;
@property(nonatomic,strong)UILabel *titleLaber;
@property(nonatomic,strong)UILabel *contentLaber;
@property(nonatomic,strong)UILabel *likeLabel;
@property(nonatomic,strong)UILabel *personLaber;
@property(nonatomic,strong)UIView *playerview;
@property(nonatomic,strong)UIImageView *likeview;
@end

@implementation CellForSPMusic

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}
-(void)createSubview{
    self.nameLaber =[[UILabel alloc] initWithFrame:CGRectMake(20, 10, WIDTH - 40, 20)];
    self.nameLaber.font = [UIFont systemFontOfSize:13];
    self.nameLaber.textColor = [UIColor grayColor];
    self.titleLaber =[[UILabel alloc] initWithFrame:CGRectMake(20, 35, WIDTH - 90, 30)];
    self.titleLaber.numberOfLines = 0;
    self.personLaber =[[UILabel alloc] init];
    self.personLaber.font =[UIFont systemFontOfSize:14];
    self.personLaber.textColor =[UIColor darkGrayColor];
    self.playerview =[[UIView alloc]initWithFrame:CGRectMake(WIDTH - 90,30 , 70, 70)];
    self.playerview.backgroundColor =[UIColor grayColor];
    self.contentLaber =[[UILabel alloc] initWithFrame:CGRectMake(20, 110, WIDTH -40, 40)];
    self.contentLaber.font = [UIFont systemFontOfSize:15];
    self.contentLaber.textColor = [UIColor darkGrayColor];
    self.contentLaber.numberOfLines = 0;
    self.likeLabel =[[UILabel alloc] init];
    self.likeLabel.font =[UIFont systemFontOfSize:13];
    self.likeLabel.textColor =[UIColor grayColor];
    self.likeview =[[UIImageView alloc]init];
    
    self.likeview.image =[UIImage imageNamed:@"iconfont-shoucangweishoucang"];
    [self.contentView addSubview:self.likeview];
    [self.contentView addSubview:self.likeLabel];
    [self.contentView addSubview:self.nameLaber];
    [self.contentView addSubview:self.titleLaber];
    [self.contentView addSubview:self.playerview];
    [self.contentView addSubview:self.personLaber];
    [self.contentView addSubview:self.contentLaber];
    
    
    
}


-(void)setBaseModel:(TXPSPBaseModel *)baseModel{
    [super setBaseModel:baseModel];
    TXPSPMusic *music =(TXPSPMusic *)baseModel;
    NSString *str =[music.name stringByAppendingString:@" · "];
    NSString *strone =[str stringByAppendingString:music.enname];
    self.nameLaber.text = strone;
    NSString *person =[music.userinfo objectForKey:@"uname"];
    self.personLaber.text =person;
    self.titleLaber.text = music.title;
    self.contentLaber.text = music.content;
    NSString *like =[NSString stringWithFormat:@"%ld",music.like];
      self.likeLabel.text = like;
#pragma mark --内容自适应高度第2步
    CGFloat height  = [TXPLBfit heightForContents:self.titleLaber.text Nsnumber:17];
    
    CGRect frame = self.titleLaber.frame;
    frame.size.height = height;
    self.titleLaber.frame = frame;
    self.personLaber.frame = CGRectMake(20, height + self.titleLaber.frame.origin.y, self.titleLaber.frame.size.width, 20) ;
    CGFloat heightcont  = [TXPLBfit heightForContents:self.contentLaber.text Nsnumber:15];
    if (heightcont >= 89.50) {
        heightcont = 89.50;
    }
    CGRect framecon = self.contentLaber.frame;
    framecon.size.height = heightcont;
    self.contentLaber.frame = framecon;

    
    [self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentLaber.mas_bottom).offset(0);
        make.right.mas_equalTo(20);
        make.left.mas_equalTo(WIDTH-50);
        make.height.mas_equalTo(20);
        
    }];
    
    [self.likeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentLaber.mas_bottom).offset(0);
        make.right.mas_equalTo(self.likeLabel.mas_left).offset(0);
        make.left.mas_equalTo(WIDTH - 70);
        make.height.mas_equalTo(17);
        
    }];
    

    
   
    
}



@end
